package com.yaozheng.vocationaltraining.view;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 签到一项月份View
 *
 * @author Administrator
 */
@EViewGroup(R.layout.view_sign_item_month)
public class SignItemMonthView extends RelativeLayout {
    @ViewById
    TextView viewSignItemTextView;
    @ViewById
    ImageView signDatabase, retroactiveSignImage;
    /**
     * 是否显示宝箱
     */
    private boolean isShowDatabase;
    /**
     * 是否签到
     */
    private boolean isSign;

    private String signDate;

    private int currDay;

    private int reId;

    public SignItemMonthView(Context context, AttributeSet attrs,
                             int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public SignItemMonthView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SignItemMonthView(Context context) {
        super(context);
    }

    public void setValue(String value) {
        viewSignItemTextView.setText(value);
    }

    public boolean isShowDatabase() {
        return isShowDatabase;
    }

    public void setShowDatabase(boolean isShowDatabase) {
        this.isShowDatabase = isShowDatabase;
    }

    public boolean isSign() {
        return isSign;
    }

    public void setSign(boolean isSign) {
        this.isSign = isSign;
    }

    public String getSignDate() {
        return signDate;
    }

    public void setSignDate(String signDate) {
        this.signDate = signDate;
    }

    public int getCurrDay() {
        return currDay;
    }

    public void setCurrDay(int currDay) {
        this.currDay = currDay;
    }

    /**
     * 显示宝箱
     */
    public void showDatabase() {
//        signDatabase.setVisibility(View.VISIBLE);
        isShowDatabase = true;
    }

    /**
     * 隐藏宝箱
     */
    public void hideDatabase() {
//        signDatabase.setVisibility(View.INVISIBLE);
        isShowDatabase = false;
    }

    /**
     * 已签到
     */
    public void signIn() {
        signDatabase.setSelected(true);
        viewSignItemTextView.setSelected(true);
        isSign = true;

    }

    public void setSignBack(int reId) {
        this.reId = reId;
        signDatabase.setBackgroundResource(reId);
    }

    /**
     * 补签点击
     */
    public void retroactive() {
        retroactiveSignImage.setVisibility(View.VISIBLE);
    }

    /**
     * 补签取消
     */
    public void unRetroactive() {
        retroactiveSignImage.setVisibility(View.GONE);
    }

    public void loadData(boolean isCurrDay) {
        if (isCurrDay) {
            if (isSign) {
                setSignBack(R.drawable.icon_now_sign);
            } else {
                setSignBack(R.drawable.icon_now);
            }
        } else {
            if (isSign && isShowDatabase) {
                //                    //签到 宝箱领了 true true
                setSignBack(R.drawable.icon_sign_box_bg);

            } else if (isSign && !isShowDatabase) {
                //                // 签到没领宝箱 true false
                setSignBack(R.drawable.icon_sign_no_box_bg);

            } else if (!isSign && isShowDatabase) {
                ////               有宝箱  false false
                setSignBack(R.drawable.icon_no_box);
            } else {
                ////               没签到   false false
                setSignBack(R.drawable.icon_no_sign_no_box_bg);

            }
        }
    }
}
